<cfcomponent output="false">
	
	<!--- --->
	
	<cffunction name="renderTimeline" access="public" output="true" returntype="string">
		<cfargument name="date" required="true" />
		
		<cfset var local = {} />
		<cfset local.weekday = {2:"M",3:"Tu",4:"W",5:"Th",6:"F",7:"Sa",1:"Su"} />
		<!--- <cfset local.dates = application.s.calendarService.getDateRangesByDate(arguments.date) /> --->
		<cfset local.dates = $.run.it('calendarService.getDateRangesByDate', {date=arguments.date}) />
		
		<cfset local.today = $.date.getDate() />
		
		<!--- calculate months and weeks --->
		<cfset local.arrayMonth = [] /><!--- count the tds in each month --->
		<cfset local.arrayWeek = [] />
		<cfset local.currentMonth = "" />
		<cfset local.currentWeek = "" />
		<cfloop array="#local.dates#" item="local.item" index="local.i">
			<cfif local.currentMonth neq month(local.item)>
				<cfset local.struct = {month:month(local.item),year:year(local.item),count:1} />
				<cfset local.currentMonth = local.struct.month />
				<cfset arrayAppend(local.arrayMonth,local.struct) />
			<cfelse>
				<cfset local.arrayMonth[arrayLen(local.arrayMonth)].count++ />
			</cfif>
			
			<cfif local.currentWeek neq week(local.item)>
				<cfset local.struct = {week:week(local.item),count:1,year:year(local.item)} />
				<cfset local.currentWeek = local.struct.week />
				<cfset arrayAppend(local.arrayWeek,local.struct) />
			<cfelse>
				<cfset local.arrayWeek[arrayLen(local.arrayWeek)].count++ />
			</cfif>
		</cfloop>

		<cfsavecontent variable="local.result">
			<table cellspacing="0" cellpadding="0" width="100%">
				<tr class="month">
					<cfloop array="#local.arrayMonth#" item="local.item" index="local.i">
						<cfset local.class = "" />
						<cfif month(local.today) eq local.item.month and year(local.today) eq local.item.year>
							<cfset local.class = local.class & ' current' />
						</cfif>
						<cfif local.i mod 2 eq 0>
							<cfset local.class = local.class & ' odd' />
						</cfif>
						<td colspan="#local.item.count#" class="#local.class#">#monthAsString(local.item.month)# #local.item.year#</td>
					</cfloop>
				</tr>
				<tr class="days">
					<cfloop array="#local.dates#" item="local.item" index="local.i">
						<cfset local.class = "" />
						<cfif local.i eq arrayLen(local.dates)><cfset local.class = local.class & ' last'></cfif>
						<cfif local.i eq 17><cfset local.class = local.class & ' center' /></cfif>
						<cfif local.i eq 18><cfset local.class = local.class & ' aftercenter'></cfif>
						<!--- <cfif week(local.item) eq week(local.today)><cfset local.class = local.class & ' thisweek' /></cfif>
						<cfif month(local.item) eq month(local.today)><cfset local.class = local.class & ' thismonth'></cfif> --->
						<cfset local.array = listToArray(local.item,'/')>
						<td class="#local.class#" <cfif arguments.date neq local.item> onclick="Calendar.showDate('#local.array[1]#','#local.array[2]#','#local.array[3]#');"</cfif> date="#$.format.date(local.item,'mmddyyyy',false)#" day="#dayOfWeek(local.item)#">
							<div class="td-day">
								<div class="timeline-events"></div>
								<cfif local.item eq local.today>
									<div class="timeline-today">today</div>
								</cfif>					
								<div class="date">#day(local.item)#</div>
								<div class="weekday">#local.weekday[dayOfWeek(local.item)]#</div>
							</div>
						</td>
					</cfloop>
				</tr>
				<tr class="week">
					<cfloop array="#local.arrayWeek#" item="local.item" index="local.i">
						<cfset local.class = "" />
						<cfif week(local.today) eq local.item.week><cfset local.class = local.class & ' current'></cfif>
						<cfif local.item.week mod 2 eq 0><cfset local.class = local.class & ' odd'></cfif>
						<td colspan="#local.item.count#" class="#local.class#">
							<cfif week(local.today) eq local.item.week and local.item.year eq year(local.today)>
								This Week
							<cfelseif week(local.today) eq (local.item.week + 1) and local.item.year eq year(local.today)>
								Last Week
							<cfelseif week(local.today) eq (local.item.week - 1) and local.item.year eq year(local.today)>
								Next Week
							<cfelse>
								Week #local.item.week#
							</cfif>
						</td>
					</cfloop>
				</tr>
			</table>
			
			<script>
				Calendar.setTimelineEvents();
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderTimelineControls" access="public" output="true" returntype="string">
		<cfargument name="date" required="true" />
		
		<cfset var local = {} />
		
		<cfset local.today = $.date.getDate() />
		<cfset local.options = $.site.getOptions('calendar') />
		<cfset local.user = $.run.it('craftivityService.getUser',{userID=request.session.user.id}) />

		<cfset local.categories = request.session.user.event_categories />
		<cfset local.filterCount = listLen(local.options.filterDays) + listLen(local.options.filterCategories) />
		
		<cfset local.days = ['SU','M','TU','W','TH','F','SA'] />
		
		<cfsavecontent variable="local.result">
			<div class="controls">
				<input name="control-today" type="hidden" value="#local.today#" />
				<input name="control-date" type="hidden" value="#arguments.date#" />
				
				<div class="controls-buttons">
					<button value="" class="small" id="show-filters" onclick="$('.controls-filters').fadeIn();$(this).fadeOut();"><cfif local.filterCount gt 0>#local.filterCount# </cfif>filter<cfif local.filterCount gt 1>s</cfif></button>
					<button value="#month(arguments.date)#" class="red small" id="timeline-month">#MonthAsString(month(arguments.date))#</button>
					<button value="#day(arguments.date)#" class="blue small" style="width:33px;" id="timeline-day">#day(arguments.date)#</button>
					<button value="#year(arguments.date)#" class="grey small" id="timeline-year">#year(arguments.date)#</button>
					<button id="timeline-today" class="yellow small" style="<cfif arguments.date eq local.today>display:none;</cfif>">Today</button>
				</div>
				
				<fieldset class="controls-filters" style="display:none;">
					<legend><i class="fa fa-times" onclick="Calendar.hideFilters();"></i>Filters</legend>
					<div class="controls-filters-day">
						<cfloop array="#local.days#" item="local.item" index="local.i">
							<button value="#local.i#" class="small <cfif local.options.filterDays contains local.i>filtered</cfif>">#local.item#</button>
						</cfloop>
					</div>
					<div class="controls-filters-category">
						<cfloop from="1" to="3" index="local.i">
							<button value="#local.i#" class="small cat#local.i# <cfif local.options.filterCategories contains local.i>filtered</cfif>">
								<cfif listLen(local.categories) gte local.i>
									#listGetAt(local.categories,local.i)#
								<cfelse>
									Category #local.i#
								</cfif>
							</button>
						</cfloop>
					</div>
					<div class="controls-filters-category">
						<cfloop from="4" to="6" index="local.i">
							<button value="#local.i#" class="small cat#local.i# <cfif local.options.filterCategories contains local.i>filtered</cfif>">
								<cfif listLen(local.categories) gte local.i>
									#listGetAt(local.categories,local.i)#
								<cfelse>
									Category #local.i#
								</cfif>
							</button>
						</cfloop>
						<button value="0" class="small cat0 <cfif local.options.filterCategories contains 0>filtered</cfif>">
							no category
						</button>
					</div>
				</fieldset>
				
				<div class="controls-months hidden">
					<div>
						<button class="small" value="01">January</button>
						<button class="small" value="02">February</button>
						<button class="small" value="03">March</button>
					</div>
					<div>
						<button class="small" value="04">April</button>
						<button class="small" value="05">May</button>
						<button class="small" value="06">June</button>
					</div>
					<div>
						<button class="small" value="07">July</button>
						<button class="small" value="08">August</button>
						<button class="small" value="09">September</button>
					</div>
					<div>
						<button class="small" value="10">October</button>
						<button class="small" value="11">November</button>
						<button class="small" value="12">December</button>
					</div>
				</div>
				
				<div class="controls-day hidden">
					<div><cfloop from="1" to="7" index="local.i">
							<button class="small" value="0#local.i#">#local.i#</button>
						</cfloop></div>
					<div>
						<button class="small" value="08">8</button>
						<button class="small" value="09">9</button>
						<cfloop from="10" to="14" index="local.i">
							<button class="small" value="#local.i#">#local.i#</button>
						</cfloop></div>
					<div><cfloop from="15" to="21" index="local.i">
							<button class="small" value="#local.i#">#local.i#</button>
						</cfloop></div>				
					<div><cfloop from="22" to="28" index="local.i">
							<button class="small" value="#local.i#">#local.i#</button>
						</cfloop></div>
					<div>
						<button value="29" class="small leap">29</button>
						<button value="30" class="small">30</button>
						<button value="31" class="small big ">31</button>
					</div>
				</div>
				
				<div class="controls-year hidden">
					<cfset local.year = year($.date.getDate()) />
					<cfset local.counter = 0 />
					<div>
					<cfloop from="#year-2#" to="#year+6#" index="local.year">
						<cfset local.counter++ />
						<button class="small" value="#local.year#">#local.year#</button>
						<cfif local.counter mod 3 eq 0>
							</div><div>
						</cfif>
					</cfloop>
					</div>
				</div>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderCalendarDays" access="public" output="true" returntype="string">
		<cfargument name="date" required="true" />
		<cfargument name="day_count" required="false" default="20" hint="inclusive for timeline AND calendar view." />
		<cfargument name="days_after_show" required="false" default="20" hint="for calendar view" />
		<cfargument name="days_before_show" required="false" default="1" hint="for calendar view"  />
		<cfargument name="requested_date" required="false" default="" />
		
		<cfset var local = {} />
		
		<cfset local.today = $.date.getDate() />
		<cfset local.date = arguments.date />
		
		<cfif arguments.requested_date neq "">
			<cfset arguments.date = arguments.requested_date />
		</cfif>
		
		<cfset local.events = $.run.it('calendarService.getEvents', {
			startdate=dateFormat(dateAdd('d',arguments.day_count * -1,local.date),'mm/dd/yyyy'),
			enddate=dateFormat(dateAdd('d',arguments.day_count,local.date),'mm/dd/yyyy')
		}) />
		
		<cfsavecontent variable="local.result">
			<cfset local.date = dateFormat(dateAdd('d',arguments.days_before_show * -1,local.date),'mm/dd/yyyy') />
			<cfloop from="1" to="#arguments.days_before_show#" index="local.i">
				#renderCalendarDay(date=local.date,events=local.events,requested_date=arguments.date)#
				<cfset local.date = dateFormat(dateAdd('d',1,local.date),'mm/dd/yyyy') />
			</cfloop>
			<cfloop from="1" to="#arguments.days_after_show#" index="local.i">
				#renderCalendarDay(date=local.date,events=local.events,requested_date=arguments.date)#
				<cfset local.date = dateFormat(dateAdd('d',1,local.date),'mm/dd/yyyy') />
			</cfloop>
			
			<div class="widget short more-events" onclick="Calendar.loadMoreEvents(this);" date="#local.date#">
				Show more events
			</div>
			
			<script>
				Calendar.activateEvents();
				Calendar.events = {};
				Calendar.eventDescriptions = {};
				<cfloop query="local.events">
					<!--- localize the UTC datetime --->
					<cfset local.event_start = $.date.applyLocalization(local.events.start_date & ' #local.events.start_time#') />
					<cfset local.event_stop = $.date.applyLocalization(local.events.start_date & ' #local.events.stop_time#') />
					<!--- format for renderEvent() --->
					<cfset local.event_date = dateFormat(local.event_start,'mm/dd/yyyy') />
					
					var date = '#local.event_date#';
					date = date.replace(/\//g,"");
					if(!(date in Calendar.events)){
						Calendar.events[date] = [];
					}
					if(!(date in Calendar.eventDescriptions)){
						Calendar.eventDescriptions[date] = "";
					}
					Calendar.events[date].push('#local.events.category#');
					<cfset local.humanizedTime = $.format.humanizeTime($.date.applyLocalization(local.events.start_date & " " & local.events.start_time),true) />
					<cfset local.description = rereplace(local.events.description,"'","\'","ALL") />
					<cfif len(local.description) gt 20>
						<cfset local.description = left(local.description,20) & ' ..' />
					</cfif>
					Calendar.eventDescriptions[date] += '#local.humanizedTime# - #local.description#';
					Calendar.eventDescriptions[date] = Calendar.eventDescriptions[date].replace(/"/g, "'");
					<cfif local.events.currentRow neq local.events.recordcount>
						Calendar.eventDescriptions[date] += "</br>";
					</cfif>
				</cfloop>
				Calendar.setTimelineEvents();
				Calendar.requested_date = '#arguments.date#';
				Calendar.applyFilters(0);
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderCalendarDay" access="public" output="true" returntype="string">
		<cfargument name="date" required="true" />
		<cfargument name="events" required="false" hint="query of events for the day" />
		<cfargument name="requested_date" required="true" />
		
		<cfset var local = {} />
		
		<cfif not structKeyExists(arguments,"events")>
			<cfset arguments.events = $.run.it('calendarService.getEvents',{
				startdate=arguments.date,
				enddate=arguments.date
			}) />
		</cfif>
		
		<cfset local.today = $.date.getDate() />
		<cfset local.eventcount = 0 />
		
		<cfsavecontent variable="local.result">
			<div class="widget day <cfif arguments.requested_date eq arguments.date>timeline-focus</cfif><cfif dateCompare(arguments.requested_date,arguments.date) eq 1>previous</cfif>" day="#dayOfWeek(arguments.date)#" date="#arguments.date#">
				<div class="day-header">
					<div class="day-date">#$.format.date(arguments.date,'mmm d',false)#</div>
					<div class="widget-title">
						#dayOfWeekAsString(dayOfWeek(arguments.date))#
						<cfif local.today eq arguments.date><span id="widget-today">(Today)</span></cfif>
						<cfif dateAdd('d',1,local.today) eq arguments.date><span id="widget-today">(Tomorrow)</span></cfif>
						<cfif dateAdd('d',-1,local.today) eq arguments.date><span id="widget-today">(Yesterday)</span></cfif>
					</div>
					<div class="day-year">#year(arguments.date)#</div>
				</div>

				<cfloop query="arguments.events">
					<!--- localize the UTC datetime --->
					<cfset local.event_start = $.date.applyLocalization(arguments.events.start_date & ' #arguments.events.start_time#') />
					<cfset local.event_stop = $.date.applyLocalization(arguments.events.start_date & ' #arguments.events.stop_time#') />
					<!--- format for renderEvent() --->
					<cfset local.event_date = dateFormat(local.event_start,'mm/dd/yyyy') />
					<cfset local.event_starttime = timeFormat(local.event_start,'HH:mm:ss') />
					<cfset local.event_stoptime = timeFormat(local.event_stop,'HH:mm:ss') />
					
					<cfif arguments.date eq local.event_date>
						<cfset local.eventcount++ />
						#renderEvent(
							id=arguments.events.id,
							description=arguments.events.description,
							starttime=local.event_starttime,
							stoptime=local.event_stoptime,
							date=local.event_date,
							category=arguments.events.category,
							requested_date=arguments.requested_date,
							google_event_id=arguments.events.google_event_id,
							google_calendar_link=arguments.events.google_calendar_link,
							google_calendar_id=arguments.events.google_calendar_id,
							parent_id=arguments.events.parent_id,
							child_events=arguments.events.child_events
						)#
					</cfif>
				</cfloop>
				
				<cfif local.eventcount eq 0>
					<div class="no-events">No Events</div>
				</cfif>

				#renderEvent(id="",date=arguments.date,requested_date=arguments.requested_date)#
				
				<div class="buttons small">
					<button class="event-add red right small">add event</button>
				</div>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderEvent" access="public" output="true" returntype="string">
		<cfargument name="id" required="true" />
		<cfargument name="description" required="false" default="" />
		<cfargument name="starttime" required="false" default="08:00:00" />
		<cfargument name="stoptime" required="false" default="08:00:00" />
		<cfargument name="category" required="false" default="0" />
		<cfargument name="date" required="true" />
		<cfargument name="requested_date" required="true" hint="so the controller can maintain focus on the date after save">
		<cfargument name="redirect" required="false" default="true" hint="if false, simply reload the page on form submit" />
		<cfargument name="google_event_id" required="false" default="" />
		<cfargument name="google_calendar_id" required="false" default="" />
		<cfargument name="google_calendar_link" required="False" default="" />
		<cfargument name="parent_id" required="false" default="" hint="indicates an event belongs to a larger set of google events - no edit" />
		<cfargument name="child_events" required="false" default="" hint="indicates an event is the lead of event of a set of google events. - no edit" />

		<cfset var local = {} />
		
		<cfset local.startFormatted = timeformat(arguments.starttime,'h:mm tt') />
		<cfset local.stopFormatted = timeformat(arguments.stoptime,'h:mm tt') />
		<cfset local.same = local.startFormatted eq local.stopFormatted />
		<cfset local.options = $.site.getOptions('calendar') />
		
		<!--- all day event display --->
		<cfif local.startFormatted eq '12:00 am' and local.stopFormatted eq '11:55 pm'>
			<cfset local.same = true />
			<cfset local.startFormatted = "<span style='color:##999999;text-decoration:underline;font-size:11px;'>ALL DAY</span>">
		</cfif>
				
		<cfsavecontent variable="local.result">
			<div class="event cat#arguments.category# <cfif arguments.id eq ''>event-new hidden</cfif>" category="#arguments.category#">
				<div class="event-show">
					<div class="event-time">
						<div class="event-starttime">#local.startFormatted#</div>
						<div class="event-endtime<cfif local.same> hidden</cfif>">#local.stopFormatted#</div>
					</div>

					<div class="event-content">
						<div>
							#$.format.paragraph(arguments.description)#
						</div>
					</div>
					
					<div class="event-controls">
						<cfif arguments.parent_id eq "" and arguments.child_events eq "">
							<button class="event-edit right small">edit</button>
						<cfelse>
							<cfif arguments.google_calendar_link neq "">
								<button 
									class="right small"
									onclick="Calendar.editEventInGoogle('#arguments.google_calendar_link#');"
									style="white-space:nowrap">
									Google Edit
								</button>
							<cfelse>
								<span style="white-space:nowrap;font-size:11px;position:absolute;bottom:0px;right:10px;">* Editable from Google</span>
							</cfif>
						</cfif>
					</div>
					
					<div class="event-category-show cat#arguments.category#">
						<cfif arguments.category gt 0>
							#listGetAt(request.session.user.event_categories,arguments.category)#
						<cfelse>
							Category
						</cfif>
					</div>
				</div>

				#renderEventForm(argumentCollection=arguments)#
				<cfif arguments.google_event_id neq "">
					<div class="event-google<cfif local.options.craftivity_calendar_id eq arguments.google_calendar_id> craftivity</cfif>" onclick="Calendar.showGoogleInfo(this);" animate="no" expanded="no">
						<div class="event-google-title">Google Calendar:</div>
						<div class="event-google-calendar">
							<i class="fa fa-times" onclick="Calendar.hideGoogleInfo(this);"></i>
							<cfif structKeyExists(local.options.google_calendars,arguments.google_calendar_id)>
								"#local.options.google_calendars[arguments.google_calendar_id].name#"
							<cfelseif local.options.craftivity_calendar_id eq arguments.google_calendar_id>
								"Craftivity"
							<cfelse>
								*Unknown*
							</cfif>
						</div>
					</div>
				</cfif>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderEventForm" access="public" output="true" returntype="string">
		<cfargument name="id" required="true" />
		<cfargument name="description" required="false" default="" />
		<cfargument name="starttime" required="false" default="08:00:00" />
		<cfargument name="stoptime" required="false" default="08:00:00" />
		<cfargument name="category" required="false" default="0" />
		<cfargument name="date" required="true" />
		<cfargument name="requested_date" required="true" hint="so the controller can maintain focus on the date after save">
		<cfargument name="redirect" required="false" default="true" hint="if false, simply reload the page on form submit" />

		<cfset var local = {} />
		
		<cfset local.start = timeFormat(arguments.starttime,'HH:mm:00') />
		<cfset local.stop = timeFormat(arguments.stoptime,'HH:mm:00') />
		<cfset local.humanStart = $.format.humanizeTime(local.start) />
		<cfset local.humanStop = $.format.humanizeTime(local.stop) />

		<cfset local.same = false />
		<cfif local.start eq local.stop><cfset local.same = true /></cfif>
		
		<cfif local.start eq '00:00:00' and local.stop eq '23:55:00'>
			<cfset local.humanStart = "all day" />
			<cfset local.humanSTop = "all day" />
		</cfif>
		
		<cfsavecontent variable="local.result">
			#$.render.form(name='event_form',method='calendarController.saveEvent',onsubmit="return Calendar.validateEvent(this);")#
				<div class="event-edit">
					<input type="hidden" name="requested_date" value="#arguments.requested_date#" />
					<input type="hidden" name="date" value="#arguments.date#" />
					<input type="hidden" name="id" value="#arguments.id#" />
					<input type="hidden" name="redirect" value="#arguments.redirect#" />
					<input type="hidden" name="google_calendar_id" value="#arguments.google_calendar_id#" />
					<input type="hidden" name="google_event_id" value="#arguments.google_event_id#" />
					<div class="event-edit-form">
						<div class="event-time-edit">
							<div class="event-edit-titles" style="border-right:1px solid ##b4b4b4;text-align:center;">Start</div>							
							<button type="button" class="event-start" onclick="Calendar.showTimepicker(this);" name="start_#arguments.id#"><span class="button-start-text">#local.humanStart#</span></button>
							<div class="event-edit-titles end">End</div>
							<button type="button" class="event-stop<cfif local.same> hidden</cfif>" onclick="Calendar.showTimepicker(this);" name="stop_#arguments.id#"><span class="button-stop-text">#local.humanStop#</span></button>
							<cfif local.same>
								<button type="button" class="event-show-stop" onclick="Calendar.showStop(this);" name="show_stop_#arguments.id#">Set</button>
							</cfif>
						</div>
						<div class="event-content-edit">
							<div class="event-edit-titles">
								Description
								<span class="category-text cat1">
									<cfif arguments.category gt 0>
										#listGetAt(request.session.user.event_categories,arguments.category)#
									<cfelse>
										Category
									</cfif>
								</span>
							</div>		
							<textarea name="description" rows="3" validate="maxLength499">#$.format.paragraph(string=arguments.description,input=true)#</textarea>
						</div>
					</div>
					
					<div class="event-controls-edit">
						<button type="button" class="left grey small event-category-button">
							<span class="category-button-text">
								<cfif arguments.category gt 0>
									#listGetAt(request.session.user.event_categories,arguments.category)#
								<cfelse>
									Category
								</cfif>
							</span>
						</button>
						<button class="left <cfif arguments.id eq ""> hidden</cfif> small" onclick="Calendar.deleteEvent(this);" type="button">delete</button>
						<button class="right red small" type="button" onclick="Calendar.saveEvent(this);">save</button>
						<button class="right grey small event-cancel" type="button">cancel</button>
						<div style="clear:both;"></div>
					</div>
				</div>
				
				<div class="event-category hidden">
					<cfloop from="1" to="6" index="local.i">
						<cfset local.thisCategory = "Category#local.i#" />
						<cfif listLen(request.session.user.event_categories) gte local.i>
							<cfset local.thisCategory = listGetAt(request.session.user.event_categories,local.i) />
						</cfif>
						<div style="height:24px;">
							<button category="#local.thisCategory#" class="event-category-select-button cat#local.i# small" type="button" value="#local.i#">
								<span class="category-button-text">#local.thisCategory#</span>
							</button>
						</div>
					</cfloop>
					<div>
						<button class="event-category-select-button small" type="button" value="0"><span class="category-button-text" style="max-width:85px;">no category</span></button>
					</div>
					<input type="hidden" name="category" value="#arguments.category#" />
				</div>

				#renderTimepicker(
					id=arguments.id,
					name='start',
					label="Start",
					stopname="stop",
					value=local.start
				)#
				#renderTimepicker(
					id=arguments.id,
					name='stop',
					label="End",
					value=local.stop,
					after=local.start
				)#
			</form>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderTimepicker" access="public" output="true" returntype="string">
		<cfargument name="id" required="true" hint="an event or weekday id"/>
		<cfargument name="name" required="true" />
		<cfargument name="label" required="false" default="" />
		<cfargument name="stopname" required="false" default="" />
		<cfargument name="value" required="false" default="" />
		<cfargument name="after" required="false" default="" />
		
		<cfset var local = {} />
		
		<cfif arguments.label eq ''>
			<cfset arguments.label = $.format.humanize(arguments.name) />
		</cfif>
		
		<cfset local.timeArray = listToArray(arguments.value,":") />
		<cfset local.hourValue = local.timeArray[1] />
		<cfset local.minuteValue = local.timeArray[2] />
		<cfset local.am = true />
		<cfif local.hourValue gt 11>
			<cfset local.am = false />
			<cfset local.hourValue = local.hourValue - 12 />
			<cfif local.hourValue lt 10>
				<cfset local.hourValue = '0' & local.hourValue />
			</cfif>
		</cfif>
		<cfif local.minuteValue mod 5 neq 0>
			<cfset local.minuteValue = local.minuteValue - (local.minuteValue mod 5) />
		</cfif>
				
		<cfsavecontent variable="local.result">
			<div class="timepicker hidden" name="#arguments.name#" id="#arguments.name#_#arguments.id#" show=".event-edit" stopname="#arguments.stopname#" <cfif arguments.after neq "">after="#arguments.after#"</cfif>>
				<table class="timepicker-table"width="100%" class="test" cellpadding="0" cellspacing="0">
					<tr class="timepicker-title">
						<td colspan="12"><i class="fa fa-times timepicker-close" onclick="Time.cancelSetTime(this);"></i>#arguments.label#</td>
					</tr>
					<tr class="timepicker-hour">
						<cfloop from="0" to="11" index="local.i">
							<cfset local.hour = local.i />
							<cfif local.hour eq 0>
								<cfset local.hour = 12 />
							</cfif>
							<td value="#local.i#" class="<cfif local.i eq local.hourValue>selected</cfif>">#local.hour#</td>
						</cfloop>
					</tr>
					<tr class="timepicker-minutes">
						<cfloop from="0" to="11" index="local.i">
							<cfset local.minute = local.i * 5 />
							<cfif local.minute lt 10>
								<cfset local.minute = '0' & local.minute />
							</cfif>
							<td value="#local.i * 5#" class="<cfif local.minute eq local.minuteValue>selected</cfif>">#local.minute#</td>
						</cfloop>
					</tr>
				</table>
				
				<table class="timepicker-ampm" cellpadding="0" cellspacing="0">
					<tr>
						<td class="timepicker-am <cfif local.am>selected</cfif>">AM</td>
						<td class="timepicker-pm <cfif not local.am>selected</cfif>">PM</td>
					</tr>
				</table>
				
				<button type="button" class="timepicker-set-allday small" onclick="Time.allDayBaby(this);">all day</button>
				
				<button type="button" class="timepicker-set-time small" onclick="Time.setTime(this);">use #timeformat(arguments.value,'h:mm tt')#</button>
				<input type="hidden" name="#arguments.name#" value="#arguments.value#" />
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderTimezoneLeft" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfset local.states = $.run.it('resourceService.getStates') />
		<cfset local.business = $.run.it('craftivityService.getBusiness',{userID=request.session.user.id}) />
		
		<cfsavecontent variable="local.result">
			<script>
				validateTimezone = function(){
					var $form = $('##leftLocationTimezoneForm');
					var timezone = $form.find('select[name=timezone]').val();
					if(timezone.length == 0){
						return false
					} else{
						return true;
					}
				};
			</script>
			<div class="module-left-element moveable edit">
				#$.render.form(name="leftLocationTimezoneForm",method="craftivityController.saveLocationTimezone",onsubmit="return validateTimezone();")#
					<div class="module-left-title"><i style="font-size:17px;" class="fa fa-calendar"></i>Calendar</div>
					<div class="widget-form-title" style="color:##666666;">Please Select Your Time Zone</div>
	
					#$.run.it('craftivityView.renderSelect',{name="stateID",label="State",value=local.business.state_ID,query=local.states,instructions="Not U.S. or Canada? Leave this empty."})#
					#$.run.it('calendarView.renderContinentSelect',{value=local.business.continent})#
					#$.run.it('calendarView.renderTimezoneSelect',{
						value=local.business.timezone
					})#
					
					<cfset local.dstMessage = "Check if you live in an are that observes Daylight Savings Time." />
					<div class="daylight-savings form-input">
						<div class="form-input-label" title="#local.dstMessage#">Observe DST</div>
						<div class="form-input-value">
							<input name="dst" type="checkbox" value="true" title="#local.dstMessage#" <cfif local.business.dst eq 1>checked</cfif> />
							<div class="form-input-instructions">
							<i class="fa fa-info-circle"></i>
								Daylight Savings Time
							</div>
						</div>
					</div>
					
					<div class="buttons">
						<input type="hidden" name="businessID" value="#local.business.id#" />
						<input type="hidden" name="name" value="#local.business.name#" />
						<button type="submit" class="right red" name="save">save</button>
					</div>
				</form>
				<div style="clear:both;"></div>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderContinentSelect" access="public" output="true" returntype="string">
		<cfargument name="name" required="false" default="continent" />
		<cfargument name="value" required="false" default="" />

		<cfset var local = {} />
		
		<cfset local.continents = queryNew("id,name") />
		
		<cfset queryAddRow(local.continents) />
		<cfset querySetCell(local.continents,'id','AF') />
		<cfset querySetCell(local.continents,'name','Africa') />
		
		<cfset queryAddRow(local.continents) />
		<cfset querySetCell(local.continents,'id','AS') />
		<cfset querySetCell(local.continents,'name','Asia') />
		
		<cfset queryAddRow(local.continents) />
		<cfset querySetCell(local.continents,'id','AU') />
		<cfset querySetCell(local.continents,'name','Australia') />
		
		<cfset queryAddRow(local.continents) />
		<cfset querySetCell(local.continents,'id','E') />
		<cfset querySetCell(local.continents,'name','Europe') />
		
		<cfset queryAddRow(local.continents) />
		<cfset querySetCell(local.continents,'id','NA') />
		<cfset querySetCell(local.continents,'name','North America') />
		
		<cfset queryAddRow(local.continents) />
		<cfset querySetCell(local.continents,'id','SA') />
		<cfset querySetCell(local.continents,'name','South America') />
		
		<cfsavecontent variable="local.result">
			#$.run.it('craftivityView.renderSelect',{
				name=arguments.name,
				value=arguments.value,
				label="Continent",
				query=local.continents,
				blank=true,
				showReadValue=true
			})#
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderTimezoneSelect" access="public" output="true" returntype="string">
		<cfargument name="value" required="false" default="" />
		<cfargument name="name" required="false" default="timezone" />

		<cfset var local = {} />
		
		<cfset local.timezones = queryNew("id,name") />

		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-10:00') />
		<cfset querySetCell(local.timezones,'name','UTC -10:00 (Hawaii)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-9:00') />
		<cfset querySetCell(local.timezones,'name','UTC -9:00 (Alaska)') />

		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-8:00') />
		<cfset querySetCell(local.timezones,'name','UTC -8:00 (Pacific)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-7:00') />
		<cfset querySetCell(local.timezones,'name','UTC -7:00 (Mountain)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-6:00') />
		<cfset querySetCell(local.timezones,'name','UTC -6:00 (Central)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-5:00') />
		<cfset querySetCell(local.timezones,'name','UTC -5:00 (Eastern)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-4:00') />
		<cfset querySetCell(local.timezones,'name','UTC -4:00 (Atlantic)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-4:30') />
		<cfset querySetCell(local.timezones,'name','UTC -4:30 (Venezuela)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-3:30') />
		<cfset querySetCell(local.timezones,'name','UTC -3:30 (Newfoundland)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-3:00') />
		<cfset querySetCell(local.timezones,'name','UTC -3:00 (W. Greenland)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-2:00') />
		<cfset querySetCell(local.timezones,'name','UTC -2:00 (Fernando de Noronha)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','-1:00') />
		<cfset querySetCell(local.timezones,'name','UTC -1:00 (Cape Verde)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+0:00') />
		<cfset querySetCell(local.timezones,'name','UTC +0:00 (Greewich Mean)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+1:00') />
		<cfset querySetCell(local.timezones,'name','UTC +1:00 (Central European)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+2:00') />
		<cfset querySetCell(local.timezones,'name','UTC +2:00 (Eastern European)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+3:00') />
		<cfset querySetCell(local.timezones,'name','UTC +3:00 (Moscow)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+3:30') />
		<cfset querySetCell(local.timezones,'name','UTC +3:30 (Iran)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+4:00') />
		<cfset querySetCell(local.timezones,'name','UTC +4:00 (Mauritius)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+4:30') />
		<cfset querySetCell(local.timezones,'name','UTC +4:30 (Afghanistan)') />
				
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+5:00') />
		<cfset querySetCell(local.timezones,'name','UTC +5:00 (Pakistan)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+5:30') />
		<cfset querySetCell(local.timezones,'name','UTC +5:30 (India)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+5:45') />
		<cfset querySetCell(local.timezones,'name','UTC +5:45 (Nepal)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+6:00') />
		<cfset querySetCell(local.timezones,'name','UTC +6:00 (Bangladesh)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+6:30') />
		<cfset querySetCell(local.timezones,'name','UTC +6:30 (Myanmar/Cocos)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+7:00') />
		<cfset querySetCell(local.timezones,'name','UTC +7:00 (Thailand)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+8:00') />
		<cfset querySetCell(local.timezones,'name','UTC +8:00 (Singapore)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+8:45') />
		<cfset querySetCell(local.timezones,'name','UTC +8:45 (Central Western)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+9:00') />
		<cfset querySetCell(local.timezones,'name','UTC +9:00 (Japan)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+9:30') />
		<cfset querySetCell(local.timezones,'name','UTC +9:30 (Australian Central)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+10:00') />
		<cfset querySetCell(local.timezones,'name','UTC +10:00 (Australian Eastern)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+10:30') />
		<cfset querySetCell(local.timezones,'name','UTC +10:30 (Lord Howe)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+11:00') />
		<cfset querySetCell(local.timezones,'name','UTC +11:00 (Vladivostok)') />
		
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+11:30') />
		<cfset querySetCell(local.timezones,'name','UTC +11:30 (Norfolk)') />
				
		<cfset queryAddRow(local.timezones) />
		<cfset querySetCell(local.timezones,'id','+12:00') />
		<cfset querySetCell(local.timezones,'name','UTC +12:00 (Magadan)') />
		
		<cfsavecontent variable="local.result">
			#$.run.it('craftivityView.renderSelect',{
				name=arguments.name,
				value=arguments.value,
				label="Time Zone",
				query=local.timezones,
				blank=arguments.value eq "",
				validate="required",
				showReadValue=true
			})#
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderGoogleSyncStatus" access="public" output="true" returntype="string">
		<cfargument name="show" required="false" default="false" />

		<cfset var local = {} />
		
		<cfset local.options = $.site.getOptions('calendar') />
		
		<cfsavecontent variable="local.result">
			<cfif local.options.refresh_token neq "" and (local.options.pullThread neq "" or local.options.pushThread neq "")>
				<div class="variable-width google-sync-status">
					<cfset local.threadStatus = $.run.it('calendarService.getGoogleThreadStatus') />
					<!--- <div>Pushing #local.pushTHreadOutcome#</div> --->
					<cfif local.threadStatus eq "RUNNING">
						<i class="fa fa-refresh fa-spin" style="font-size:13px;"></i>
						<div class="google-sync-status-text">Syncing with Google Calendar. Please wait...</div>
					<cfelseif local.threadStatus eq 'ERROR'>
						<i class="fa fa-refresh fa-exclamation" style="font-size:13px;"></i>
						<div class="google-sync-status-text">Error Syncing to Google Calendar...</div>
					<cfelse>
						<div></div>
					</cfif>
				</div>
				<!--- run this to refresh if threads still working --->
				<cfif local.threadStatus eq 'RUNNING'>
					<script>
						setTimeout(function(){
							Ajax.run({
								method:"calendarView.renderGoogleSyncStatus",
								onsuccess:function(data){
									$('.variable-width.google-sync-status').replaceWith(data);
								},
								args:{show:'true'}
							});
							Ajax.run({
								method:"calendarView.renderGoogleRefresh",
								onsuccess:function(data){
									$('##google_refresh_link').replaceWith(data);
								}
							});
						},10000);
					</script>
				</cfif>
			<cfelseif arguments.show>
				<!--- if threads complete, give alert --->
				<div class="variable-width google-sync-status">
					<div class="google-sync-status-text" style="color:rgb(122, 195, 63);">Google Sync Completed. Please <a href="javascript:location.reload();">Refresh</a> this page.</div>
				</div>
			</cfif>
		</cfsavecontent>
		
		<cfreturn local.result />
		
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderGoogleRefresh" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfset local.threadStatus = $.run.it("calendarService.getGoogleThreadStatus") />
		<cfset local.options = $.site.getOptions('calendar') />
		
		<cfsavecontent variable="local.result">
			<cfif local.options.initial_sync_complete eq true and local.options.last_synced_on neq "">
				<cfif local.threadStatus eq "ERROR">
					<div id="google_refresh_link" style="color:rgb(228, 98, 98);">
						Error Syncing to Google Calendar
						<a bubble="Retry Sync" href="javascript:$('form[name=refresh_calendar]').submit();">
							<i class="fa fa-refresh" style="color:rgb(228, 98, 98);margin:3px;"></i>
						</a>
					</div>
				<cfelseif local.threadStatus eq "RUNNING">
					<div id="google_refresh_link" style="color:rgb(231, 112, 39);">
						Syncing to Google Calendar
						<i class="fa fa-refresh fa-spin" style="color:rgb(231, 112, 39);margin:3px;cursor:default;"></i>
					</div>
				<cfelse>
					<div id="google_refresh_link">
						<cfset local.syncDate = dateFormat($.date.applyLocalization(local.options.last_synced_on),'mm/dd/yyyy') />
						Updated <cfif local.syncDate neq $.date.getDate()>#$.format.humanizeDate($.date.applyLocalization(local.options.last_synced_on))# </cfif>at #$.format.humanizeTime($.date.applyLocalization(local.options.last_synced_on))#
						<a bubble="Sync with Google Calendar" href="javascript:$('form[name=refresh_calendar]').submit();">
							<i class="fa fa-refresh" style="margin:3px;"></i>
						</a>
					</div>
				</cfif>
			</cfif>
		</cfsavecontent>
		
		<cfreturn local.result />
		
	</cffunction>
	
	<!--- --->

</cfcomponent>